<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Database
 *
 * @author Administrator
 */
require_once '../core/ConsoleLogUtil.php';

class Database {

    //put your code here
    private $host;
    private $port;
    private $user;
    private $password;
    private $dbname;
    private $conn;

    public function __construct() {
        $this->host = "localhost";
        $this->port = "3306";
        $this->user = "root";
        $this->password = "P@ssw0rd";
        $this->dbname = "backbone";
    }

    public function getConnection() {
        // Create connection
        $this->conn = mysql_connect($this->host, $this->user, $this->password, $this->dbname);

        // Check connection
        if (!$this->conn) {
            ConsoleLogUtil::error(mysql_error($this->conn));
            echo "Failed to connect to MySQL: " . mysql_error($this->conn);
        }
        
        if(!mysql_select_db($this->dbname, $this->conn)) {
            ConsoleLogUtil::error(mysql_error($this->conn));
        }

        return $this->conn;
    }

    public function close() {
        mysql_close($this->conn);
    }

}
